package com.ds.dsm.view.nav.service;

import com.ds.common.JDSException;
import com.ds.config.TreeListResultModel;
import com.ds.dsm.view.nav.service.tabs.NavTabsTree;
import com.ds.dsm.view.nav.service.tree.CustomTreeTree;
import com.ds.dsm.view.nav.tree.NavActionConfigTree;
import com.ds.esd.custom.api.annotation.APIEventAnnotation;
import com.ds.esd.custom.bean.ApiClassConfig;
import com.ds.esd.custom.bean.MethodConfig;
import com.ds.esd.custom.enums.CustomMenuItem;
import com.ds.esd.custom.module.annotation.ModuleAnnotation;
import com.ds.esd.dsm.DSMFactory;
import com.ds.esd.dsm.view.ViewEntityConfig;
import com.ds.esd.tool.ui.component.list.TreeListItem;
import com.ds.esd.util.TreePageUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Controller
@RequestMapping("/dsm/view/config/foldingtree/")
public class ViewNavFoldingTreeConfigService {


    @RequestMapping(method = RequestMethod.POST, value = "ViewFoldIngTreeFieldConfig")
    @ModuleAnnotation(dynLoad = true, caption = "获取字段列", imageClass = "bpmfont bpmgongzuoliuxitongpeizhi", index = 0)
    @APIEventAnnotation(bindMenu = CustomMenuItem.loadChild)
    @ResponseBody
    public TreeListResultModel<List<TreeListItem>> getViewFoldIngTreeFieldConfig(String domainId, String sourceClassName, String methodName, String viewInstId) {
        TreeListResultModel<List<TreeListItem>> result = new TreeListResultModel<>();
        try {
            List<TreeListItem> items = new ArrayList<>();
            ViewEntityConfig classConfig = DSMFactory.getInstance().getViewManager().getViewEntityConfig(sourceClassName, viewInstId);
            ApiClassConfig customESDClassAPIBean = classConfig.getSourceConfig();
            MethodConfig methodAPIBean = customESDClassAPIBean.getMethodByName(methodName);
            List<MethodConfig> cMethods = Arrays.asList(methodAPIBean);
            items.addAll(TreePageUtil.fillObjs(cMethods, CustomTreeTree.class));
            items.addAll(TreePageUtil.fillObjs(cMethods, NavTabsTree.class));
            items.addAll(TreePageUtil.fillObjs(cMethods, NavActionConfigTree.class));
            result.setData(items);
        } catch (JDSException e) {
            e.printStackTrace();
        }
        return result;
    }

//
//    @MethodChinaName(cname = "视图信息")
//    @RequestMapping(method = RequestMethod.POST, value = "ViewEntityInfo")
//    @NavGroupViewAnnotation
//    @APIEventAnnotation(bindMenu = CustomMenuItem.treeNodeEditor)
//    @ModuleAnnotation(dock = Dock.fill, caption = "装载", imageClass = "spafont spa-icon-c-grid")
//    @ResponseBody
//    public ResultModel<ViewInfoGroup> getViewEntityInfo(String viewInstId, String domainId, String sourceClassName) {
//        ResultModel<ViewInfoGroup> result = new ResultModel<ViewInfoGroup>();
//        return result;
//    }


}
